package test.ui {
	import gear.core.Game;
	import gear.net.LibData;
	import gear.net.RESManager;
	import gear.net.SWFLoader;
	import gear.ui.cell.LabelSource;
	import gear.ui.controls.GButton;
	import gear.ui.controls.GList;
	import gear.ui.core.ScaleMode;
	import gear.ui.data.GButtonData;
	import gear.ui.data.GIconData;
	import gear.ui.data.GListData;

	import flash.events.Event;
	import flash.events.MouseEvent;

	/**
	 * TestGList 测试列表控件
	 * 
	 * @author bright
	 * @version 20101012
	 */
	[SWF(width=1000,height=570,backgroundColor=0x333333,frameRate=30)]
	public class TestGList extends Game {
		private var _list : GList;
		private var _add_btn : GButton;
		private var _remove_btn : GButton;
		private var _test_btn : GButton;

		override protected function startup() : void {
			RESManager.instance.add(new SWFLoader(new LibData("assets/ui.swf")));
			RESManager.instance.addEventListener(Event.COMPLETE, completeHandler);
			RESManager.instance.load();
		}

		private function completeHandler(event : Event) : void {
			RESManager.instance.removeEventListener(Event.COMPLETE, completeHandler);
			addList();
			addButtons();
			initEvents();
		}

		private function addList() : void {
			var data : GListData = new GListData();
			data.x = 10;
			data.y = 10;
			data.scaleMode = ScaleMode.AUTO_SIZE;
			data.cellData.width = 100;
			data.cellData.height = 22;
			_list = new GList(data);
			addChild(_list);
			_list.model.source = [new LabelSource("item0"), new LabelSource("item1")];
		}

		private function addButtons() : void {
			var data : GButtonData = new GButtonData();
			data.x = 10;
			data.y = 150;
			data.width = 45;
			data.height = 24;
			data.labelData.text = "增加";
			_add_btn = new GButton(data);
			data = data.clone();
			data.x = 60;
			data.labelData.text = "删除";
			var iconData : GIconData = new GIconData();
			data.labelData.iconData = iconData;
			_remove_btn = new GButton(data);
			data = data.clone();
			data.x = 110;
			data.labelData.text = "测试";
			_test_btn = new GButton(data);
			addChild(_add_btn);
			addChild(_remove_btn);
			addChild(_test_btn);
		}

		private function initEvents() : void {
			_add_btn.addEventListener(MouseEvent.CLICK, add_clickHandler);
			_remove_btn.addEventListener(MouseEvent.CLICK, remove_clickHandler);
			_test_btn.addEventListener(MouseEvent.CLICK, testClickHandler);
		}

		private function add_clickHandler(event : MouseEvent) : void {
			_list.model.add(new LabelSource("added_0", 0));
		}

		private function remove_clickHandler(event : MouseEvent) : void {
			_list.model.removeAt(0);
		}

		private function testClickHandler(event : MouseEvent) : void {
			_list.show();
		}

		public function TestGList() {
			super();
		}
	}
}
